#pragma once
#include "types.h"
#ifndef __ASSEMBLER__

static inline size_t
r_sp()
{
  size_t x;
  asm volatile("mv %0, sp" : "=r" (x) );
  return x;
}

// read and write tp, the thread pointer, which xv6 uses to hold
// this core's hartid (core number), the index into cpus[].
static inline size_t
r_tp()
{
  size_t x;
  asm volatile("mv %0, tp" : "=r" (x) );
  return x;
}

static inline void 
w_tp(size_t x)
{
  asm volatile("mv tp, %0" : : "r" (x));
}

static inline size_t
r_ra()
{
  size_t x;
  asm volatile("mv %0, ra" : "=r" (x) );
  return x;
}

#endif // __ASSEMBLER__

#define PGSIZE 4096 // bytes per page

// one beyond the highest possible virtual address.
// MAXVA is actually one bit less than the max allowed by
// Sv39, to avoid having to sign-extend virtual addresses
// that have the high bit set.
#define MAXVA (1L << (9 + 9 + 9 + 12 - 1))
